<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>水费查询</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../plugins/mui/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/life_housekeeper/wate_index.css" />
		<script src="../../js/statistics.js"></script>
		<script src="../../js/fontset.js"></script>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav header">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">水费查询</h1>
		</header>
		<div class="mui-content">
			<form action="#" onsubmit="sub()">
				<div class="water-img">
					<img src="../../images/icon/life_housekeeper/water-rate-bg.png" class="img-response"/>
					<div class="search-group">
						<p class="search-tit">请输入您的户号，进行水费查询</p>
						<div class="search-view-cell">
							<label for="user" class="search-label">户号&nbsp;:</label>
							<input type="number" placeholder="请输入用户号" class="search-input input-defalut" id="userCode"/>
						</div>
					</div>
				</div>
			</form>
			<div class="mui-text-center btn-box">
				<button class="mui-btn button-primary" id="searchSub">查询</button>
			</div>
			
		</div>
		<script src="../../plugins/mui/mui.min.js"></script>
		<script src="../../js/getApiToken.js"></script>	
		<script src="../../js/md5.js"></script>
		<script src="../../js/life_housekeeper/windowTitleView.js"></script>
		<script>
			mui.init();
			mui.plusReady(function(){
				plus.nativeUI.showWaiting();
				//实名认证 每次都需要实时获取 除了已经认证成功
				if(plus.storage.getItem('cg_certification')!=1){
					myAjax('personal/user_profile/getselfprofile', 'get', {
						'user_id': plus.storage.getItem('cg_user_id'),
						'user_token': plus.storage.getItem('cg_user_token')
					}, function(data) {
						plus.nativeUI.closeWaiting();
						if(!data.success){
							plus.nativeUI.alert(data.error_msg, function() {
								mui.back();
							}, "错误", "确定");
							return ;//发生错误 就直接退出
						}
						plus.storage.setItem('cg_certification', data.certification);
						var certification = plus.storage.getItem('cg_certification') ;
						var	confirmArray = ['前往认证','稍后认证'];
						if(certification==-1){
							mui.confirm('您尚未进行实名认证，无法进行水费查询。','实名认证',confirmArray,function(e){
								if(e.index == 0){
									var self = plus.webview.currentWebview();
									self.close();
									mui.openWindow({
									    url:'../my/user-4-1.html',
									    id:'user-4-1.html',
									     show:{
										      autoShow:false,//页面loaded事件发生后自动显示，默认为true
										      duration:200//页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
										},
										 waiting:{
									      	title:'正在加载...'//等待对话框上显示的提示内容
									     }
									});	
									return;
								}
								mui.back();
							})
						}else{
							if(certification == 0){
								mui.alert('您的实名认证正在审核中，请耐心等待。','实名认证','确定',function(e){									
									mui.back();
								})
							}else if(certification == 2){
								mui.confirm('您的实名认证未通过，请重新认证。','实名认证',confirmArray,function(e){
									if(e.index == 0){
										var self = plus.webview.currentWebview();
										self.close();
										mui.openWindow({
										    url:'../my/user-4.html',
										    id:'user-4.html',
										     show:{
											      autoShow:false,//页面loaded事件发生后自动显示，默认为true
											      duration:200//页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
											},
											 waiting:{
										      	title:'正在加载...'//等待对话框上显示的提示内容
										     }
										});	
										return;
									}
									mui.back();
								})
							}else if(certification == 1){
								console.log(certification);
								
								var searchSub = document.getElementById("searchSub");
								searchSub.addEventListener('tap',function(){	
					                sub();
								},false);
							}
						}
					});
				}else{
					plus.nativeUI.closeWaiting();
					var searchSub = document.getElementById("searchSub");
					searchSub.addEventListener('tap',function(){	
		                sub();
					},false);
				}

				
//			    console.log(plus.navigator.getStatusBarBackground());
			})
			function sub(){
				var userCode = document.getElementById("userCode");
		    	var value = userCode.value;
		    	 
		    	if(!value || value==""){
		    		mui.toast("请输入户号!");
		    		return;
		    	}else{
		    		var reg = new RegExp("^[0-9]*$");
		    		if(!reg.test(value)){
				        mui.toast("请输入数字!");
				        return;
				    }else{
				    	var data ={
							'code':value.trim()
						};
						plus.nativeUI.showWaiting();
		 				myAjax('home/water/arrears_new','get',data,function(result){
		 					var res = result.data;
		 					console.log(res);
			                if(result.code == 1){
			                	mui.toast("查询失败，未查询到该户号相关水费信息");
			                	plus.nativeUI.closeWaiting();
			                	return;
			                }else{
			                	var viewOptions = {
									url:'water_query.html',
									id:'water_query'
								},						              
								extras ={
									data:res
								},
								titleOptions = {
									title:'水费查询',
									backImg:'whiteBack'
								};
								mui.addTitleView(viewOptions,extras,titleOptions);
							}	
		 				})
				    }
		    	}	
		    }

		</script>
	</body>
</html>
